#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <climits>
#include <numeric>
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

template<class Flow>
struct Maxflow {
	static const Flow INF = ~0U >> 1; //should change with type
//	static const Flow INF = numeric_limits<Flow>::max();
	struct Edge {
		int t;
		Flow c;
		Edge*n, *r;
		Edge(int _t, Flow _c, Edge*_n) :
				t(_t), c(_c), n(_n) {
		}
	};
	vector<Edge*> E;

	int addV() {
		E.push_back((Edge*) 0);
		return E.size() - 1;
	}

	void clear() {
		E.clear();
	}

	Edge* makeEdge(int s, int t, Flow c) {
		return E[s] = new Edge(t, c, E[s]);
	}

	void addEdge(int s, int t, Flow c) {
		Edge*e1 = makeEdge(s, t, c), *e2 = makeEdge(t, s, 0);
		e1->r = e2, e2->r = e1;
	}

	int calcMaxFlow(int vs, int vt) {
		int nV = E.size();
		Flow totalFlow = 0;

		vector<Flow> am(nV, 0);
		vector<int> h(nV, 0), cnt(nV + 1, 0);
		vector<Edge*> prev(nV, (Edge*) 0), cur(nV, (Edge*) 0);
		cnt[0] = nV;

		int u = vs;
		Edge*e;
		am[u] = INF;
		while (h[vs] < nV) {
			for (e = cur[u]; e; e = e->n)
				if (e->c > 0 && h[u] == h[e->t] + 1)
					break;
			if (e) {
				int v = e->t;
				cur[u] = prev[v] = e;
				am[v] = min(am[u], e->c);
				u = v;
				if (u == vt) {
					Flow by = am[u];
					while (u != vs) {
						prev[u]->c -= by;
						prev[u]->r->c += by;
						u = prev[u]->r->t;
					}
					totalFlow += by;
					am[u] = INF;
				}
			} else {
				if (!--cnt[h[u]])
					break;
				h[u] = nV;
				for (e = E[u]; e; e = e->n)
					if (e->c > 0 && h[e->t] + 1 < h[u]) {
						h[u] = h[e->t] + 1;
						cur[u] = e;
					}
				++cnt[h[u]];
				if (u != vs)
					u = prev[u]->r->t;
			}
		}

		return totalFlow;
	}

	~Maxflow() {
		for (int i = 0; i < (int)E.size(); ++i) {
			for (Edge*e = E[i]; e;) {
				Edge*ne = e->n;
				delete e;
				e = ne;
			}
		}
	}
};

int const maxn = 202;
int c[maxn];

int main()
{
	int n, m;
	while (cin >> n) {
		vector<vector<int> > data;
		data.resize(n);
		m = 0;
		map<int, int> dis;

		for (int i = 0, num; i < n; i++) {
			cin >> num; cin >> c[i]; cin >> c[i];
			data[i].resize(num);
			for (int j = 0; j < num; j++) {
				cin >> data[i][j];
				if (!dis[data[i][j]]) dis[data[i][j]] = ++m;
			}
		}
		int tmp;
		cin >> tmp;

		int s = 0, t = n + m + 1;
		Maxflow<int> sap;
		for (int i = 0; i < n; i++) {
			sap.addEdge(s, i+1, c[i]);
			for (int j = 0; j < (int)data[i].size(); j++)
				sap.addEdge(i+1, dis[data[i][j]] + n, 1);
		}

		for (int i = 1; i <= m; i++)
			sap.addEdge(n + i, t, 1);

		std::cout << sap.calcMaxFlow(s, t) << '\n';
	}
}

